package com.lumingfeng.controller;

import com.lumingfeng.entity.In;
import com.lumingfeng.service.InService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by chengyin on 16/8/16.
 */
@RequestMapping(value = "/in")
@Controller
public class InController {

    @Resource(name = "inService")
    private InService inService;

    @RequestMapping("/list")
    public ModelAndView list(){
        List<In> inList = inService.select();
        ModelAndView view =new ModelAndView("in_list");
        view.addObject("inlist",inList);

        return view;
    }

    @RequestMapping("/add")
    public  ModelAndView add(){

            ModelAndView view =new ModelAndView("in_add");
            return view;
    }

    @RequestMapping("/save")
    public  ModelAndView save(In in){

        Integer result = inService.save(in);
        if (result == 1) {
            ModelAndView view =new ModelAndView("in_list");
            view.addObject("inlist",inService.select());
            return view;
        } else {
            return null;
        }
    }
}
